// 引入模块
const conn = require('../data/gy_index');
// 显示登录页面
module.exports.gy_login = (req, res) => {
   res.render('gy_login');
}
// 登录
module.exports.userlogin = (req, res) => {
   let sql = 'select * from users where gy_phone=? and gy_password=?';
   let data = [req.query.phone, req.query.password];
   conn.query(sql, data, (eer, result) => {
      if (eer) return console.log(eer);
      if (result.length == 0) {
         res.json({
            code: '1201',
            message: '账号或者密码错误'
         });
      } else if (result.length != 0) {
         req.session.isgaoyuan = true;
         req.session.users = result[0];
         res.json({
            code: '1202',
            message: '登录成功'
         });
      }
      // console.log(result);
   })
}
// 退出
module.exports.outlogin = (req, res) => {
   req.session.destroy(function (eer) {
      if (eer) {
         return console.log(eer);
      }
      res.redirect('/gy_login');
   })
}